package com.kakaxi.mybilibili.module.home.find.presenter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kakaxi.mybilibili.bean.FindHomeTagItemBean;
import com.kakaxi.mybilibili.common.WebParamConst;
import com.kakaxi.mybilibili.module.home.find.model.FindHomeModel;
import com.kakaxi.mybilibili.module.home.find.model.IFindHomeModel;
import com.kakaxi.mybilibili.module.home.find.view.IFindHomeView;
import com.kakaxi.mybilibili.utils.LogUtil;
import com.vincestyling.netroid.Listener;
import com.vincestyling.netroid.NetroidError;

import java.util.List;

/**
 * 发现首页面控制层实现类
 * Created by kakaxi on 16/11/27.
 */

public class FindHomePresenter implements IFindHomePresenter {

    private IFindHomeModel mModel;

    private IFindHomeView mView;

    public FindHomePresenter(IFindHomeView findHomeView) {
        mView = findHomeView;
        mModel = new FindHomeModel();
    }

    @Override
    public void initTagData() {
        mModel.getTagData(new Listener<JSONObject>() {

            @Override
            public void onSuccess(JSONObject response) {
                super.onSuccess(response);
                if (response.getString(WebParamConst.RESPONSE_CODE).equals(WebParamConst
                        .RESULT_CODE_OK)) {
                    JSONArray tagJsonArr = response.getJSONArray(WebParamConst
                            .RESPONSE_DATA_FIND_HOME_LIST);
                    List<FindHomeTagItemBean> tagItemBeanList = JSON.parseArray(tagJsonArr
                            .toString(), FindHomeTagItemBean.class);
                    mView.showTagData(tagItemBeanList);
                } else {
                    LogUtil.d(response.getString(WebParamConst.RESPONSE_MESSAGE));
                }
            }

            @Override
            public void onError(NetroidError error) {
                super.onError(error);
            }
        });
    }

}
